﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LGE;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;

namespace Stealth
{
    public class InteractiveObject : GameObject
    {
        #region Static
        public const String UpStairs = "upstairs";
        public const String DownStairs = "downstairs";
        public const String Exit = "exit";
        public const String Door = "door";
        public const String Coffee = "coffee";
        public const String Plant = "plant";

        public static String Folder = "Images\\Interactives\\";
        static Dictionary<String, Texture2D> sprites = new Dictionary<string, Texture2D>() { { UpStairs, Engine.Load<Texture2D>(Folder + UpStairs) },
                                                                                             { DownStairs, Engine.Load<Texture2D>(Folder + DownStairs) },
                                                                                             { Exit, Engine.Load<Texture2D>(Folder + Door) },
                                                                                             { Coffee, Engine.Load<Texture2D>(Folder + Door) },
                                                                                             { Plant, Engine.Load<Texture2D>(Folder + Door) },
                                                                                             { Door, Engine.Load<Texture2D>(Folder + Door) }};
        static Dictionary<String, Texture2D> spritesGlow = new Dictionary<string, Texture2D>(){ { UpStairs, Engine.Load<Texture2D>(Folder + UpStairs + "_glow") },
                                                                                                { DownStairs, Engine.Load<Texture2D>(Folder + DownStairs + "_glow") },
                                                                                                { Exit, Engine.Load<Texture2D>(Folder + Door + "_glow") },
                                                                                                { Coffee, Engine.Load<Texture2D>(Folder + Door + "_glow") },
                                                                                                { Plant, Engine.Load<Texture2D>(Folder + Door + "_glow") },
                                                                                                { Door, Engine.Load<Texture2D>(Folder + Door + "_glow") }};
        #endregion

        public String name;
        public String type;
        public bool isGlowing = false;
        public bool isOccupied = false; // apenas para portas

        public InteractiveObject(PlayScreen ps, MapObject mapObj)
            : base(ps, sprites[GetObjectType(mapObj.Name)])
        {
            name = mapObj.Name;
            position = mapObj.Position;
            type = GetObjectType(mapObj.Name);
        }

        static String GetObjectType(String name)
        {
            if (name.Contains(UpStairs))
                return UpStairs;
            if (name.Contains(DownStairs))
                return DownStairs;
            if (name.Contains(Door))
                return Door;
            if (name.Contains(Exit))
                return Exit;
            if (name.Contains(Coffee))
                return Coffee;
            if (name.Contains(Plant))
                return Plant;
            return "";
        }

        public Vector2 GetOtherStairPosition()
        {
            String n = name.Replace(UpStairs, "").Replace(DownStairs, ""); // pega o número dessa escada, ou seja: pega o nome da atual e remove "downstairs" e "upstairs"
            String newType = type == UpStairs ? DownStairs : UpStairs; // pega qual o tipo dessa escada (up ou down), de acordo com a escada atual
            foreach (InteractiveObject obj2 in newType == UpStairs ? ps.StairsUp : ps.StairsDown)
                if (obj2.name.Contains(newType) && obj2.name.Contains(n))
                    return obj2.position;
            return position;
        }

        public override void Draw(SpriteBatch spriteBatch)
        {
            base.Draw(spriteBatch);
            if (isGlowing)
                spriteBatch.Draw(spritesGlow[type], drawPosition, null, Color.White, rotation, new Vector2(spritesGlow[type].Width, spritesGlow[type].Height) / 2, scale , SpriteEffects.None, 0);
        }
    }
}